// 小程序胶囊/占位宽
const getMenuButtonWidth = () => {
	let menuButtonWidth = 0;
	// #ifdef MP-WEIXIN
	let menuButtonInfo = uni.getMenuButtonBoundingClientRect().left
	let systemInfo = uni.getSystemInfoSync().windowWidth
	menuButtonWidth = systemInfo - menuButtonInfo
	// #endif
	return menuButtonWidth;
}
// 导航栏
const getSystemInfo = () => {
	let globalData = {
		statusBarHeight: 0, // 状态导航栏高度
		navWidth: 0, //宽度
		navHeight: 0, // 总体高度
		navigationBarHeight: 0, // 导航栏高度(标题栏高度) 
		windowHeight: 0,
		navTop: 0,
	};
	// 状态栏高度
	globalData.statusBarHeight = uni.getSystemInfoSync().statusBarHeight
	globalData.navWidth = uni.getSystemInfoSync().windowWidth
	globalData.navTop = globalData.statusBarHeight + 10
	globalData.navHeight = uni.getSystemInfoSync().statusBarHeight + 10
	// #ifdef MP-WEIXIN
	// 获取微信胶囊的位置信息 width,height,top,right,left,bottom
	const custom = wx.getMenuButtonBoundingClientRect()
	// 导航栏高度(标题栏高度) = 胶囊高度 + (顶部距离 - 状态栏高度) * 2
	globalData.navHeight = custom.height + (custom.top - uni.getSystemInfoSync().statusBarHeight) * 2
	globalData.navTop = custom.top + 3
	console.log("导航栏高度：" + globalData.navHeight, custom, globalData)
	// #endif
	console.log("导航栏高度：" + JSON.stringify(globalData), globalData)
	return globalData

}

const checkSubscribe = (ids = []) => {
	return new Promise((resolve) => {
		uni.requestSubscribeMessage({
			tmplIds: ids, // 需要订阅的模板消息ID列表
			success: (res) => {
				console.log(res);
			},
			fail: (err) => {
				console.error(err)
			}
		})
	})
}

export default {
	getMenuButtonWidth,
	getSystemInfo,
	checkSubscribe
}